package com.mouse.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mouse.entity.DoubleAlleles;
import com.mouse.entity.DoubleAllelesGeneAllele;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mouse.entity.GeneAllele;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author godson
 * @since 2022-08-07
 */
public interface DoubleAllelesGeneAlleleMapper extends BaseMapper<DoubleAllelesGeneAllele> {

    @Select("SELECT * FROM(Select DISTINCT daga.* FROM (SELECT gcom.* FROM gene_category gca LEFT JOIN genecategory_genecomposition gg ON gca.gid=gg.gid LEFT JOIN gene_composition gcom ON gg.gcid=gcom.gcid WHERE gca.gid=#{gid}) gcom_result\n" +
            "LEFT JOIN gene_composition_double_alleles gcomda ON gcom_result.gcid=gcomda.gcid LEFT JOIN double_alleles da on gcomda.did=da.did "+
            "LEFT JOIN double_alleles_gene_allele daga ON da.did=daga.did) a WHERE a.daid IS NOT NULL")
    List<DoubleAllelesGeneAllele> getDoubleAllelesGeneAlleleByGid( @Param("gid") Long gid);


    @Select("SELECT daga.* FROM (SELECT da.* FROM gene_composition gcom LEFT JOIN gene_composition_double_alleles gcda ON gcom.gcid=gcda.gcid LEFT JOIN double_alleles da ON gcda.did=da.did WHERE gcom.gcid=#{gcid}) gc_result\n" +
            "LEFT JOIN double_alleles_gene_allele daga ON gc_result.did = daga.did ")
    List<DoubleAllelesGeneAllele> getDoubleAllelesGeneAlleleByGcid(@Param("gcid") Long gcid);
    /***
     * 3.2.3
     * @param did
     * @return
     */
    @Select("SELECT daga.* FROM double_alleles da LEFT JOIN double_alleles_gene_allele daga ON da.did=daga.did WHERE da.did=#{did}")
    List<DoubleAllelesGeneAllele> getDoubleAllelesGeneAlleleByDid(@Param("did") Long did);

    @Select("SELECT daga.* FROM gene_allele ga LEFT JOIN double_alleles_gene_allele daga ON ga.aid=daga.aid WHERE daga.aid=#{aid}")
    List<DoubleAllelesGeneAllele> getDoubleAllelesGeneAlleleByAid(@Param("aid") Long aid);

}
